package com.example.lantaiyuan.myfirstapplication;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by lantaiyuan on 2017/7/14.
 */


import java.util.zip.Inflater;

public class TeacherAdapter extends ArrayAdapter<Teacher> {
    public TeacherAdapter(Context context, int resource, List<Teacher> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        // 获取老师的数据
        Teacher teacher = getItem(position);

        // 创建布局
        View oneTeacherView = LayoutInflater.from(getContext()).inflate(R.layout.teacher_item, parent, false);

        // 获取ImageView和TextView
        ImageView imageView = (ImageView) oneTeacherView.findViewById(R.id.teacher_small_imageView);
        TextView textView = (TextView) oneTeacherView.findViewById(R.id.teacher_name_textView);

        // 根据老师数据设置ImageView和TextView的展现
        imageView.setImageResource(teacher.getImageId());
        textView.setText(teacher.getName());

        return oneTeacherView;
    }

    //    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//
//        // 获取老师的数据
//        Teacher teacher = getItem(position);
//
//        // 创建布局
//        View oneTeacherView = LayoutInflater.from(getContext()).inflate(R.layout.teacher_item, parent, false);
//
//        // 获取ImageView和TextView
//        ImageView imageView = (ImageView) oneTeacherView.findViewById(R.id.teacher_small_imageView);
//        TextView textView = (TextView) oneTeacherView.findViewById(R.id.teacher_name_textView);
//
//        // 根据老师数据设置ImageView和TextView的展现
//        imageView.setImageResource(teacher.getImageId());
//        textView.setText(teacher.getName());
//
//        return oneTeacherView;
//    }
}